const WebService = require("../sercice/WebService")


const WebControl = {
    find_essay: async (req, res) => {
        try {
            const result = await WebService.find_essay_list(req.params.category, req.params.skp)
            res.status(200).send({
                msg: "获取成功",
                data: result,
                code: 200
            })
        } catch (error) {
            res.status(411).send({
                msg: "获取失败",
                data: [],
                code: 200
            })
        }
    },
    find_music: async (req, res) => {
        try {
            const result = await WebService.find_music_list(req.params.skp)
            res.status(200).send({
                msg: "获取成功",
                data: result,
                code: 200
            })
        } catch (error) {
            res.status(411).send({
                msg: "获取失败",
                data: [],
                code: 411
            })
        }
    },
    find_music_one: async (req, res) => {

        try {
            const result = await WebService.find_one(req.params.skp)
            res.status(200).send({
                msg: "获取成功",
                data: {
                    music_one: result.music_one,
                    count: result.count
                },
                code: 200
            })
        } catch (error) {
            res.status(411).send({
                msg: "获取成功",
                data: {},
                code: 411
            })
        }
    },
    fond_videos: async (req, res) => {
        try {
            const result = await WebService.find_video_list(req.params.id)
            res.send({
                msg: '获取成功',
                code: 200,
                data: result
            })
        } catch (error) {
            res.send({
                msg: '获取失败',
                code: 411,
                data: []
            })
        }
    },
    find_recommend: async (req, res) => {
        try {
            const result = await WebService.find_essay_recommend()
            res.status(200).send({
                msg: "获取成功",
                data: result,
                code: 200
            })
        } catch (error) {
            res.status(411).send({
                msg: "获取失败",
                data: [],
                code: 411
            })
        }
    },
    getOneEssay: async (req, res) => {
        try {
            const result = await WebService.findOneEssay(req.params.id)
            res.status(200).send({
                msg: "获取成功",
                data: result,
                code: 200
            })
        } catch (error) {
            console.log(error, '??????')
            res.status(411).send({
                msg: "获取失败",
                data: '???',
                code: 411
            })
        }
    },
    getOneVideo: async (req, res) => {
        try {
            console.log(req.params)
            const result = await WebService.findOneVideo(req.params.id)
            console.log(result)
            res.status(200).send({
                msg: "获取成功",
                data: result,
                code: 200
            })
        } catch (error) {
            console.log(error, '??????')
            res.status(411).send({
                msg: "获取失败",
                data: '???',
                code: 411
            })
        }
    },
    getAblums: async (req, res) => {
        try {
            const result = await WebService.find_images(req.params)
            console.log(req.body)
            res.status(200).send({
                msg: "获取成功",
                data: result,
                code: 200
            })
        } catch (error) {
            res.status(411).send({
                msg: "获取失败",
                data: [],
                code: 411
            })
        }
    },
    getTalk: async (req, res) => {
        try {
            const result = await WebService.find_talk(req.params.skp, req.params.year)
            res.status(200).send({
                msg: "获取成功",
                data: result,
                code: 200
            })
        } catch (error) {
            res.status(411).send({
                msg: "获取事变",
                data: [],
                code: 411
            })
        }
    },
    get_sepak_diffrent_year: async (req, res) => {
        try {
            const result = await WebService.speak_diffrent_year()
            console.log(result, '????')
            res.send({
                data: result
            })
        } catch (error) {
            res.send({
                data: "result"
            })
        }
    },
    get_talk_diffrent_year: async (req, res) => {
        try {
            const result = await WebService.ablums_diffrent_year()
            res.status(200).send({
                mes: "获取成功",
                data: result,
                code: 200
            })
        } catch (error) {
            res.status(411).send({
                mes: "获取失败",
                data: "",
                code: 411
            })
        }
    },
    //管理员
    findone_admin: async (req, res) => {
        try {
            const result = await WebService.find_admin()
            console.log(result, '????')
            res.status(200).send({
                mes: "获取成功",
                data: result,
                code: 200
            })
        } catch (error) {
            res.status(200).send({
                mes: "获取失败",
                data: '',
                code: 411
            })
        }
    },
    find_counts: async (req, res) => {
        try {
            const result = await WebService.find_count()
            console.log(result)
            res.status(200).send({
                msg: "获取成功",
                data: result,
                code: 200
            })
        } catch (error) {
            res.status(411).send({
                msg: "获取失败",
                data: '',
                code: 411
            })
        }

    },
    add_message: async (req, res) => {
        try {
            const result = await WebService.message_img(req.body)
            console.log(result, '??')
            res.status(200).send({
                msg: "添加成功",
                data: result,
                code: 200
            })
        } catch (error) {
            res.status(411).send({
                msg: "添加失败",
                data: '',
                code: 411
            })
        }

    },
    get_message_list: async (req, res) => {
        try {
            const result = await WebService.get_messages()
            res.status(200).send({
                msg: "获取成功",
                data: result,
                code: 200
            })
        } catch (error) {
            res.status(411).send({
                msg: "获取失败",
                data: [],
                code: 411
            })
        }
    },
    views_add: async (req, res) => {
        try {
            const result = await WebService.add_review(req.params.id)
            res.status(200).send(
                {
                    msg: "更新成功",
                    data: '',
                    code: 200
                }
            )
        } catch (error) {
            res.status(411).send(
                {
                    msg: "更新失败",
                    data: '',
                    code: 411
                }
            )
        }
    },
    discuss_add: async (req, res) => {
        try {
            const result = await WebService.add_discuss(req.params.id)
            res.status(200).send({
                msg: "更新成功",
                data: "",
                code: 200
            })
        } catch (error) {
            res.status(411).send({
                msg: "更新失败",
                data: "",
                code: 411
            })
        }
    },
    video_review: async (req, res) => {
        try {
            const result = await WebService.add_video_review(req.params.id)
            res.status(200).send({
                msg: "更新成功",
                data: "",
                code: 200
            })
        } catch (error) {
            res.status(411).send({
                msg: "更新失败",
                data: "",
                code: 411
            })
        }
    },
    videoDis_add: async (req, res) => {
        try {
            const result = await WebService.add_video_disc(req.params.id)
            res.status(200).send({
                msg: "更新成功",
                data: "",
                code: 200
            })
        } catch (error) {
            res.status(411).send({
                msg: "更新失败",
                data: "",
                code: 411
            })
        }
    },
    search_essay: async (req, res) => {
        try {
            console.log(req.body.word)
            const result = await WebService.search_essays(req.body.word)
            // console.log(result)
            res.status(200).send({
                msg: "获取成功",
                data: result,
                code: 200
            })
        } catch (error) {
            // console.log(error)
            res.status(200).send({
                msg: "获取失败",
                data: [],
                code: 411
            })
        }

    },
    test2: async (req, res) => {
        const result = await WebService.test()
        res.status(200).send({
            msg: "ok",
            data: result
        })
    }
}

module.exports = WebControl